package com.yh.wcx.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.yh.wcx.Constant.MyConstant;
import com.yh.wcx.entity.Student;
import com.yh.wcx.service.StudentSevice;
import com.yh.wcx.to.StudentTo;
import com.yh.wcx.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import java.util.List;

@Controller
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentSevice studentSevice;

    @GetMapping("/queryWithcourse/{id}")
    @ResponseBody
    public R queryStudentWithCourse(@PathVariable("id") Long id){
        Student student = studentSevice.queryStudentWithCourses(id);
        if(student!=null){
          return R.ok(MyConstant.SUCESS_MESSAGE,student);
        }{
          return R.error(MyConstant.FAIL_MESSAGE);
        }
    }

    @PutMapping("/insert")
    @ResponseBody
    public R insertStudent(@RequestBody StudentTo studentTo){
        return studentSevice.insertStudent(studentTo);
    }

    @PostMapping("/update")
    @ResponseBody
    public R updateStudent(@RequestBody StudentTo studentTo){
        return studentSevice.updateStudent(studentTo);
    }

    @GetMapping("/query/{id}")
    @ResponseBody
    public R queryStudentById(@PathVariable("id") Long id){
        return studentSevice.queryStudentById(id);
    }


    @DeleteMapping("/del/{id}")
    @ResponseBody
    public R delStudentById(@PathVariable("id") Long id){
        return studentSevice.delStudentById(id);
    }


}
